<? include 'server_config.php'; 

if($_SESSION['user_idx'] == "")
{
	?>
	<script>
		location.href='login.php';
	</script>
	<?
	return;
}


if($show_idx=="")
{
	$show_idx=$user_idx;
}

if($show_idx != $user_idx)
{
	$readonly = true;
}
else
{
	$readonly = false;
}




//사용자 이미지
$user_img = "./upload/member_photo/".$show_idx;

if(!file_exists($user_img)){
	$user_img = "./img/default_user_img.jpg";
}


//별명
$sql_2="
	SELECT nickname FROM ndd_user WHERE user_idx = $show_idx LIMIT 1;
";
		
$result_2 = mysql_query($sql_2,$connect);

$row2 = mysql_fetch_row($result_2);

$show_nickname = $row2[0];


//성별
$sql_2="
	SELECT birthday, sex, introduce FROM ndd_user_expand WHERE user_idx = $show_idx LIMIT 1;
";
		
$result_2 = mysql_query($sql_2,$connect);

$row2 = mysql_fetch_row($result_2);

if($row2[1]=="M")
	$show_sex= "남";
else if($row[1]=="F")
	$show_sex= "여";
else 
	$show_sex= "(미입력)";


//나이
if($row[0]!="0000-00-00" && $row2[0]!="")
{
	//생일 입력
	$myBirthDate    = strtotime($row2[0]);

	//만나이
	$birthDate1     = date( 'Ymd', $myBirthDate );
	$nowDate1       = date('Ymd');
	$age1           = floor(($nowDate1 - $birthDate1) / 10000);

	//한국 나이
	$birthDate2     = date( 'Y', $myBirthDate );
	$nowDate2       = date('Y');
	$age2           = $nowDate2 - $birthDate2 + 1 ;

	$show_age = $age2;
}
else
{
	$show_age = "(미입력)";

}

//자기소개

$show_introduce = $row2[2];

//류마티스 점수

$sql3="
	SELECT score, symptom_1, symptom_2, symptom_3, symptom_4, symptom_5, symptom_6, symptom_7
	
	FROM ndd_ra_score_input
	WHERE user_idx = $show_idx

	ORDER BY reg_timestamp DESC LIMIT 1
	;
";

//echo $sql3;

$result3 = mysql_query($sql3,$connect);
$row = mysql_fetch_row($result3);
$ra_score = $row[0];


$symptom_count = 0;
$symptoms = "";

if($row[1]==1)
{
	if($symptom_count!=0) $symptoms.=",";
	$symptoms.="'조조강직'";
	$symptom_count++;
}
if($row[2]==1)
{
	if($symptom_count!=0) $symptoms.=",";
	$symptoms.="'부기(종창)'";
	$symptom_count++;
}
if($row[3]==1)
{
	if($symptom_count!=0) $symptoms.=",";
	$symptoms.="'조기피로'";
	$symptom_count++;
}
if($row[4]==1)
{
	if($symptom_count!=0) $symptoms.=",";
	$symptoms.="'손저림'";
	$symptom_count++;
}
if($row[5]==1)
{
	if($symptom_count!=0) $symptoms.=",";
	$symptoms.="'불안'";
	$symptom_count++;
}
if($row[6]==1)
{
	if($symptom_count!=0) $symptoms.=",";
	$symptoms.="'불면'";
	$symptom_count++;
}
if($row[7]==1)
{
	if($symptom_count!=0) $symptoms.=",";
	$symptoms.="'우울'";
	$symptom_count++;
}
	
		


//증상시작

$sql="
	SELECT q4 FROM ndd_disease_basic WHERE user_idx = $show_idx AND disease_idx = 0 LIMIT 1;
";

//echo $sql;
$result = mysql_query($sql,$connect);
$row = mysql_fetch_row($result);
$first_report_date = $row[0];


//최근 진단일

$sql="
	SELECT reg_timestamp FROM ndd_cure WHERE user_idx = $show_idx AND disease_idx = 0 LIMIT 1;
";

//echo $sql;
$result = mysql_query($sql,$connect);
$row = mysql_fetch_row($result);
$last_report_date = substr($row[0],0,10);






?>	

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel="stylesheet" type="text/css" href="css/5_1.css"/>
	<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
	<script type="text/javascript" src="js/5_1.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			DataInput.initialize();

			// 데이터 입력 ($show_idx의 회원) - 2011-11-27 ht
			//DataInput.defaultDataInput();
			
			Data.chart_update = "<?=$last_report_date?>";
			Data.src_profileimg = "<?=$user_img?>";	

			Data.nickname = "<?=$show_nickname?>";
			Data.sex = "<?=$show_sex?>";	
			Data.age = "<?=$show_age?>";	
			Data.ra_score = "<?=$ra_score?>";
			//Data.member_score = "2";
			
			Data.member_info = "<?=$show_introduce?>";
			Data.weight = "75";
			Data.target_weight = "66";
			Data.first_report_date = "<?=$first_report_date?>";
			Data.last_report_date = "<?=$last_report_date?>";

			Data.hospital_list = [];//['서울대학변원', 'NextDoorDoctor'];
			Data.cure_list = /*[['유한레트트렉세이트정 2.5 mg','일주일 1회 (67일 남음)'],
							  ['플린정 1 mg','일주일 1회 (43일 남음)'],
							  ['아라바정 20 mg','하루 3회 (27일 남음)'],
							  ['아스피린 300 mg','하루 1회 (31일 남음)']];*/

							  [
								  <?



									$first_drug = true;
									$sql="
										SELECT B.ProductNameKr, A.dosage_fq FROM ndd_drug A, ndd_list_drug B WHERE A.user_idx = $show_idx AND A.disease_idx = 0 
											AND A.list_drug_idx = B.list_drug_idx ORDER BY start_date DESC;
									";

									$result = mysql_query($sql,$connect);
									while($row = mysql_fetch_row($result))
									{
										if(!$first_drug) echo ",";

										echo "['".$row[0]."','".$row[1]."']";



										$first_drug = false;
									}

								  ?>


							  ];
			Data.symptom_list = [<?=$symptoms?> ];
			
			// 데이터 입력 끝

			DataInput.onRenderingData();

		});
	</script>
		
	<title>Next Door Doctor</title>
</head>
<body>
	<div id="header">
		<div id="header_content">
	<?
	include "top_menu.php";
    ?>
			<div id="header_navigation"></div>
			<div id="header_notice">
				<img id="notice_icon" src="images/top_icon_input.png" alt="top icon">
				<div id="notice">귀하의 차트는 <span id="chart_update"></span>일 전에 업데이트 되었습니다</div>

				<? if($readonly) { ?>
				<a id="notice_img" href="5_1.php">
					<img src="images/button_view_my_chart.png" alt="view my chart" border='0'/>
				</a>
				<? } ?>
			</div>
		</div>
	</div>
	<div id="body">
		<div id="body_content">
			<div id="self_info">
				<dl id="self_default">
					<dt id="user_info">
						<img id="profile_img" alt="User's Profile Image"/>
						<span id="nickname"></span>
					</dt>
					<dd id="user_info_list">
						<dl id="user_info_list_detail">
							<dt id="sex" class="side_list_title"></dt>
							<dd id="age"></dd>
							<dt class="side_list_title">류마점수</dt>
							<dd id="rm_score_side"></dd>
							<!--dt class="side_list_title">회원등급</dt>
							<dd id="member_score"></dd-->
						</dl>
					</dd>
				</dl>
				<div id="self_info_left">
					<dl id="self_intro">
						<dt class="title">자기소개</dt>
						<dd id="self_intro_content"></dd>
					</dl>
					<dl id="self_health">
						<dt class="title">건강정보</dt>
						<dd>
							<dl>
								<dt class="list_title">류마 점수</dt>
								<dd id="rm_score"></dd><dd class="clear"></dd>
								<!--dt class="list_title">목표 체중</dt>
								<dd id="target_weight"></dd><dd class="clear"></dd-->
								<dt class="list_title">첫 증상</dt>
								<dd id="first_symptom"></dd><dd class="clear"></dd>
								<dt class="list_title">최근 진단</dt>
								<dd id="recent_check"></dd><dd class="clear"></dd>
							</dl>
						</dd>
					</dl>
				</div>
				<div id="self_info_right">
					<dl id="self_medi">
						<dt class="title">증상·치료</dt>
						<dd>
							<dl>
								<dt class="list_title">현재 병원</dt>
								<dd id="present_hospital"></dd><ins class="clear"></ins>
								<dt class="list_title">현재 치료</dt>
								<dd id="present_treatment"></dd><ins class="clear"></ins>
								<dt class="list_title">현재 증상</dt>
								<dd id="present_symptom"></dd><ins class="clear"></ins>
							</dl>
						</dd>
					</dl>
				</div>
			</div>
			<div class="clear"></div>
			<div id="bmi_graph">
				<dl class="side_info" id="bmi_side_info">
					<dt class="side_contents">BMI 그래프</dt>
					<ins class="side_line"></ins>
					<dd id="bmi_side_01">고도비만</dd>
					<dd id="bmi_side_02">비만</dd>
					<dd id="bmi_side_03">정상</dd>
					<dd id="bmi_side_04">저체중</dd>
					<dt class="side_contents">BMI 설명</dt>
					<ins class="side_line"></ins>
					<dd id="bmi_definition">
						BMI 질량 지수란<br>
						이러이러하고<br>
						이러이러해서<br>
						이러이러하며 종종<br>
						이러이러한 것을<br>
						의미한다
					</dd>
				</dl>
				<dl class="main_info" id="bmi_graph_info">
					<dt class="title">BMI 그래프</dt>
					<dd class="content">
						<ul class="time_tab">
							<li><a>1개월</a></li>
							<li><a>3개월</a></li>
							<li><a>6개월</a></li>
							<li><a>1년</a></li>
							<li><a>모두</a></li>
						</ul>
						<iframe>BMI graph</iframe>
					</dd>
				</dl>
			</div>
			<div class="clear"></div>
			<div id="medi_graph">
				<dl class="side_info" id="medi_side_info">
					<dt class="side_contents">약·치료 그래프</dt>
					<dd id="medi_side_01">MTX</dd>
					<ins class="side_line"></ins>
					<dd id="medi_side_02">아바타셉트</dd>
					<ins class="side_line"></ins>
					<dd id="medi_side_03">아스피린</dd>
					<ins class="side_line"></ins>
					<dd id="medi_side_04">물리치료</dd>
					<ins class="side_line"></ins>
					<dd id="medi_side_05">MRI</dd>
				</dl>
				<dl class="main_info" id="medi_graph_info">
					<dt class="title">약·치료 그래프</dt>
					<dd class="content">
						<ul class="time_tab">
							<li><a>1개월</a></li>
							<li><a>3개월</a></li>
							<li><a>6개월</a></li>
							<li><a>1년</a></li>
							<li><a>모두</a></li>
						</ul>
						<iframe>MEDI graph</iframe>
					</dd>
				</dl>
			</div>
			<div class="clear"></div>
			<div id="rm_graph">
				<dl class="side_info" id="rm_side_info">
					<dt class="side_contents">BMI 그래프</dt>
					<ins class="side_line"></ins>
					<dd id="rm_side_01">심각</dd>
					<dd id="rm_side_02">경미</dd>
					<dd id="rm_side_03">정상</dd>
					<dt class="side_contents">류마티스 설명</dt>
					<ins class="side_line"></ins>
					<dd id="rm_definition">
						류마티스 점수란<br>
						이러이러하고<br>
						이러이러해서<br>
						이러이러하며 종종<br>
						이러이러한 것을<br>
						의미한다
					</dd>
				</dl>
				<dl class="main_info" id="rm_graph_info">
					<dt class="title">류마티스 그래프</dt>
					<dd class="content">
						<ul class="time_tab">
							<li><a>1개월</a></li>
							<li><a>3개월</a></li>
							<li><a>6개월</a></li>
							<li><a>1년</a></li>
							<li><a>모두</a></li>
						</ul>
						<iframe>Rheumatism graph</iframe>
					</dd>
				</dl>
			</div>
		</div>
	</div>
	<div id="footer">
	</div>
</body>
</html>